package com.av.client;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;

import com.av.client.frames.LoginFrame;
import com.av.client.panels.MainMenuPanel;

@SuppressWarnings("serial")
public class AvDesktop extends JFrame {

	private static final int WIDTH = 800;
	private static final int HEIGHT = 500;
	private static AvDesktop instance;

	private MainMenuPanel toolbar;
	private JDesktopPane desktop;

	public static AvDesktop getInstance() {
		if (instance == null) {
			instance = new AvDesktop();
		}

		return instance;
	}// getInstance

	// Constructores

	private AvDesktop() {
		super("Administracion Vehicular");
		initComponents();

		LoginFrame.getInstance().setVisible(true);
	}// AvDesktop

	// Funciones

	private void initComponents() {
		setLayout(new GridBagLayout());
		GridBagConstraints gc = new GridBagConstraints();

		// Toolbar
		gc.anchor = GridBagConstraints.FIRST_LINE_START;
		toolbar = new MainMenuPanel();
		add(toolbar, gc);

		// Desktop
		gc.gridy = 1;
		gc.weightx = 1.0;
		gc.fill = GridBagConstraints.BOTH;
		gc.weightx = 1.0;
		gc.weighty = 1.0;
		desktop = new JDesktopPane();
		desktop.setBackground(Color.GRAY);
		desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
		add(desktop, gc);

		desktop.add(LoginFrame.getInstance());

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(WIDTH, HEIGHT);
		setLocationRelativeTo(null);
	}// initComponents

	public void addDesktop(JComponent jc) {
		if (desktop != null) {
			desktop.add(jc);
		}
	}// addDesktop

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		AvDesktop ea = AvDesktop.getInstance();
		ea.setVisible(true);
	}// main
}// AvDesktop